1. Technical Field
The present invention relates to a method inlining in a compiler, particularly to a method inlining in Java (a trademark of Sun Microsystems) JIT (Just In Time) compiler, etc.
2. Prior Art
Java includes a security check facility in its language, wherein SecurityManager class comprises the following five methods:
(1) getClassContext
This is a method for returning as an array a class which a method corresponding to each frame on a stack belongs to. A frame is a storage area which stores information generated when a method is executed, about the method generated.
(2) currentClassLoader
This method returns a class loader itself of the newest class which has a class loader and which a method corresponding to a frame on a stack belongs to. A class loader is a class comprising a group of methods used to load classes which are not yet loaded. The newest means most recently executed.
(3) currentLoadedClass
This method returns the newest class which has a class loader and which a method corresponding to a frame on a stack belongs to.
(4) currentDepth
This method returns the depth in a stack of a frame corresponding to the newest method belonging to the same class as the specified one.
(5) classLoaderDepth
This method returns the depth of a frame in a stack, wherein the frame corresponds to a method belonging to the newest class with a class loader.
These methods acquire necessary information by tracing the stack. On the other hand, method inlining takes a code of the invoked method into the invoking side at the time of compiling instead of invoking a method at the time of execution to remove method invocation. Accordingly, there is no execution information generated as to any method which is already inlined. If any method of SecurityManager class is included in any code of inlined methods or in any method invoked from the inlined method, there arises a problem that the behavior of the program may change because they don""t return the correct results. Thus, conventionally method inlining was executable only if it is assured that invocation relationship to the end is completely grasped and such method invocations do not include any call to a method of SecurityManager class.
In an object oriented language such as Java, messages are easily overloaded. Accordingly, while it has high reusability and flexibility as a module, it is almost difficult for a compiler to perform analysis which enables the aforementioned assurance. Java allows a final descriptor to be affixed to a special method. This xe2x80x9cfinalxe2x80x9d means being at the end and not to be overloaded. If the final attribute is not specified, a generally used virtual method invocation cannot specify an invoked code since it may be overridden. If method inlining is performed based on the final attribute, however, the extent to which method inlining is applicable is limited due to the following status. (a) A general programmer seldom uses the final attribute, and (b) even if the creator of a program recognizes it as a method invocation not to be overridden, in many cases there is no explicit designation of the final attribute.
Meanwhile, xe2x80x9ca method invocation wherein invocation relationship to the end is completely graspedxe2x80x9d is a method invocation wherein an invoked method is not a native method and is invoked by either a static invocation, a non-virtual invocation or a virtual method invocation with the final attribute. The native method is a method written in a language other than Java such as C and consists of a compiled code. Also, the static invocation is an invocation for a method defined with a static descriptor affixed (static method). The static method is a method for invocation without using an object, not overloaded by any other method. Accordingly, it is always possible in a static invocation to uniquely decide an executed method.
Accordingly, an object of the present invention is to expand the scope of execution optimization by method inlining in a language with a security facility such as Java.
It is also an object to enable method inlining in Java""s JIT (Just In Time) compiler.
In addition, it is also an object to enable stack information in a state where method inlining is not executed to reappear, when method inlining is executed.
It is also an object, in a language such as Java, to enable looping by a tail recursion for a method including an invocation of a method whose process after its invocation is indefinite and which includes a self recursion.
Furthermore, it is also an object to enable grasping of the number of iterations in the looping.
It is also an object to enable preservation of the invocation relationship information between methods before method inlining, when method inlining is executed.
It is also an object to enable determination of which method""s code is being executed when method inlining is executed.
To accomplish the above objects, the present invention has the following aspects. The first aspect comprises the steps of: generating a code necessary for looping by a tail recursion for a method including an invocation of a method whose process after its invocation is indefinite and which includes a self recursion; and generating a code for counting the number of iterations of the loop. By executing a program including such codes, the number of iterations of the loop can be counted so that a depth of a stack may be corrected when SecurityManager operates. Accordingly, in a language such as Java, it is also possible to attempt optimization by means of looping by a tail recursion.
The step of generating the code for counting the number of iterations of the loop may include a step of generating a work area on a stack when executing the program. It is also possible to generate a code for initializing the count of the number of the iterations of the loop before the code necessary for looping. In addition, it may also include a step of setting a flag which represents generation of a code necessary for looping in order to facilitate detection of this process being executed when SecurityManager operates.
On the other hand, if a program including an invocation of a method whose process after its invocation is indefinite and which includes a self recursion is executed, wherein the program includes a first method which includes a code necessary for looping by a tail recursion and a code for counting the number of iterations of the loop, in order to detect a depth of a frame associated with a specified method which satisfies a predetermined condition in a storage area storing information with respect to executed methods as corresponding frames, SecurityManager executes the steps of: determining whether a second method associated with a currently examined frame in the storage area is the specified method; if the second method is not the specified method, determining whether the second method is the first method; and if the second method is the first method, correcting the depth of a frame in the storage area associated with the second method by using the count value by the code for counting the number of iterations of the loop. By doing so, there will be no influence when method inlining by a tail recursion is performed. By correcting by the count value, it enables stack information in a state where inlining is not performed to reappear.
Moreover, if the second method is the specified method and a frame associated with the first method is already examined before examining a frame associated with the specified method, it further executes a step of returning a depth from an earliest frame in the storage area to a frame associated with the second method, wherein the depth is corrected by the count value in the first method. This is the process in the event of tracing a stack more deeply than in the previous paragraph.
In addition, if the second method is not the first method, it may further execute a step of adding 1 to the depth and changing the second method to a method associated with a next frame. Stack trace is performed until the specified method is detected or tracing of all the frames in the stacks is complete.
Meanwhile, if the first method includes a flag representing that it includes a code necessary for looping, it is sufficient to check whether or not there is the flag when determining if the second method is the first method.
The second aspect of the present invention comprises the steps of: inlining a code of a first method to a second method including an invocation of the first method whose process after its invocation is indefinite; getting the invocation relationship information between the first and the second methods in a state before inlining the code of the first method, and storing the invocation relationship information into a storage area available later; and when the code of the inlined first method is executed, generating a code for storing information about the first method being executed. Accordingly, when SecurityManager operates, it becomes possible to determine the invocation relationship between the methods in a state before method inlining and which method""s code is being used, which expands the scope of execution optimization by method inlining.
In order to distinguish from the first method, it is also possible, when executing a code included in the second method before inlining, to further include a step of generating a code for storing information about the second method being executed. In addition, as to the invocation relationship between the first and the second methods, it is also possible that an item associated with the first method include a pointer pointing at an item associated with the second method.
If a program including a plurality of methods is executed, wherein the plurality of methods include a first method and a second method, and the second method includes an invocation of the first method whose process after its invocation is indefinite, and the second method includes a code of the first method by the method inlining and a code for storing information about the first method being executed when the code of the inlined first method is executed, and the program includes the invocation relationship information between the first and the second methods in a state before inlining the code of the first method, in order to detect a frame associated with a specified method which satisfies a predetermined condition in a storage area storing information with respect to executed methods as corresponding frames, SecurityManager executes the steps of: determining whether a third method associated with a currently examined frame in the storage area is the second method; if the third method is the second method, getting the invocation relationship information associated with the second method; getting a corresponding item of the third method in the invocation relationship information; by using the corresponding item of the third method, getting an invoking method of the third method; and determining whether the invoking method is the specified method. By doing so, the influence of method inlining is removed since it enables stack information in a state where inlining is not performed to reappear even when method inlining is performed.
Moreover, if the invoking method is not the specified method, a step may be executed to get a further invoking method from the corresponding item of the invoking method in the invocation relationship information. Similar to the first aspect, stack trace is performed until the specified method is detected or tracing of all the frames in the stacks is complete.
Meanwhile, both the first and the second aspects of the present invention assume that they are performed for Java""s bytecode by a JIT compiler while it is also possible to be executed for an intermediate code in a JIT compiler. Also, in case of other languages, it is possible to execute it for a program written by a programmer by a normal compiler.
While the processing flow of the present invention has been explained as above, it is also possible to implement the present invention by the devices for performing such processes or a program to have a computer execute such processes. It is a normal practice for the one having ordinary skills in the art to store this program in a storage medium such as a floppy disk or a CD-ROM or any other storage devices.